public class Main {
    private static Stream constant(String s) {
        return new Const(s);
    }

    private static Stream disjunction(Stream s1, Stream s2) {
        return new Disj(s1, s2);
    }

    private static Stream catenation(Stream s1, Stream s2) {
        return new Cat(s1, s2);
    }

    private static Stream kleeneStar(Stream s) {
        return new Star(s);
    }

    public static void main(String[] args) {
        Stream a = constant("a");
        Stream b = constant("b");
        Stream c = kleeneStar(a);
        //Stream d = kleeneStar(b);
        //Stream e = catenation(c, b);
        Stream s = catenation(c, b);

        String curr;
        for (int i = 0; i < 20; ++i) {
            curr = s.next();
            System.out.println(curr);
        }
        System.out.println();
        for (int i = 0; i < 20; ++i) {
            curr = s.prev();
            System.out.println(curr);
        }
        System.out.println();
        for (int i = 0; i < 20; ++i) {
            curr = s.next();
            System.out.println(curr);
        }
    }
}
